<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formCommonScriptAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{ $ti18('rxList.moreBtn','更多') }}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="formCommonScriptEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn',"编辑")}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formCommonScriptDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>过滤</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.useTo','用途')">
<!--                            <a-input :placeholder="i18n('form.useTo','请选择用途','select')" v-model="queryParam.Q_use_to__S_LK"/>-->
                            <a-select :placeholder="i18n('form.useTo','请选择用途','select')" v-model="queryParam.Q_use_to__S_LK" :options="useToList" ></a-select>
                        </a-form-item>
<!--                        <a-form-item :label="i18n('form.category','分类')">
                            <a-input :placeholder="i18n('form.category','请选择分类','select')" v-model="queryParam.Q_category__S_EQ"/>
                        </a-form-item>-->
                        <a-form-item :label="i18n('form.name','名称')">
                            <a-input :placeholder="i18n('form.name','请输入名称','input')" v-model="queryParam.Q_name__S_LK"/>
                        </a-form-item>

                        <a-form-item :label="i18n('form.type','脚本类型')">
                            <a-select :placeholder="i18n('form.type','请选择脚本类型','select')" v-model="queryParam.Q_type__I_EQ"
                                      :options="typeList"></a-select>
<!--                            <a-input-number :min="0" :max="1000000" :placeholder="i18n('form.type','脚本类型','select')"
                                            v-model="queryParam.Q_type__I_EQ"/>-->
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formCommonScript/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                  <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                            <span @click="edit(record)">{{$ti18('rxList.editBtn',"编辑")}}</span>
                            <span @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                  </span>
                  <span slot="useTo" slot-scope="{ text, record }" class="actionIcons">
                            <span>{{ useToObj[text] }}</span>
                  </span>
                  <span slot="type" slot-scope="{ text, record }" class="actionIcons">
                            <span>{{ scriptType[text] }}</span>
                  </span>
                    <span slot="name" slot-scope="{ text, record }" class="actionIcons">
                            <span>{{ $i18(text,"国际化名称") }}</span>
                  </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormCommonScriptApi from '@/api/form/core/formCommonScript'
import FormCommonScriptEdit from './FormCommonScriptEdit'
import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormCommonScriptList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.useTo','用途'), dataIndex: 'useTo', width: 80, scopedSlots: {customRender: 'useTo'}},
                {title: this.i18n('form.category','分类'), dataIndex: 'category', width: 100},
                {title: this.i18n('form.name','名称'), dataIndex: 'name', width: 120,scopedSlots: {customRender: 'name'}},
                {title: this.i18n('form.type','脚本类型'), dataIndex: 'type', width: 80, scopedSlots: {customRender: 'type'}},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: FormCommonScriptEdit,
            comment: "常用脚本",
            widthHeight: ['800px', '650px'],
            fitSearch: false,
            useToObj: {
                "common": this.i18n("category.common","通用函数"),
                "list-pcJs": this.i18n("category.pcJs","列表PC端JS函数"),
                'list-mobileJs': this.i18n("category.mobileJs","列表移动端JS函数"),
                "list-bolistBtn": this.i18n("category.bolistBtn","列表功能按钮"),
                "form-solutionScript": this.i18n("category.solutionScript","表单方案脚本配置"),
                "form-designJs": this.i18n("category.designJs","表单设计JS脚本"),
                "portal-customPortal": this.i18n("category.customPortal","门户组件脚本"),
                "bpm-nodeConfig": this.i18n("category.nodeConfig","流程节点脚本"),
                "portal-customPage": this.i18n("category.customPage","自定义栏目脚本"),
                "formSolution": this.i18n("category.formSolution","表单方案脚本"),
                "formSolution-button": this.i18n("category.formSolutionButton","表单方案按钮脚本"),
                "formBoListExcel":this.i18n("category.formBoListExcel","列表Excel脚本")
            },
            scriptType: {
                "0": this.i18n("form.frontScript","前端脚本"),
                "1": this.i18n("form.backScript","后端脚本"),
                "2": this.i18n("form.mobileScript","移动端脚本")
            },
            typeList:[
                {label: this.i18n("form.frontScript","前端脚本"), value: 0},
                {label: this.i18n("form.backScript","后端脚本"), value: 1},
                {label: this.i18n("form.mobileScript","移动端脚本"), value: 2},
            ],
            useToList:[
                {label: this.i18n("category.common","通用函数"), value: 'common'},
                {label: this.i18n("category.pcJs","列表PC端JS函数"), value: 'list-pcJs'},
                {label: this.i18n("category.formBoListExcel","列表Excel脚本"),value:"formBoListExcel"},
                {label: this.i18n("category.mobileJs","列表移动端JS函数"), value: 'list-mobileJs'},
                {label: this.i18n("category.bolistBtn","列表功能按钮"), value: 'list-bolistBtn'},
                {label: this.i18n("category.designJs","表单设计JS脚本"), value: 'form-designJs'},
                {label: this.i18n("category.customPortal","自定义栏目脚本"), value: 'portal-customPortal'},
                {label: this.i18n("category.customPage","自定义页面脚本"), value: 'portal-customPage'},
                {label: this.i18n("category.nodeConfig","流程节点脚本"), value: 'bpm-nodeConfig'},
                {label: this.i18n("category.formSolution","表单方案"), value: 'formSolution'},
                {label: this.i18n("category.formSolutionButton","表单方案按钮脚本"), value: 'formSolution-button'},
            ],
        }
    },
    created() {
        FormCommonScriptApi.getCommonScriptByUse("list").then(res => {
            console.log(res)
        });
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "commonScript", key);
        },
        delById(ids) {
            return FormCommonScriptApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormCommonScriptApi.query(parameter)
        }

    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

